package downstream

import (
	"context"
	"inventory/api/bilinadmin"
	"inventory/api/bmember"
	"inventory/api/open"
	"inventory/api/prod"
	"inventory/internal/conf"
)

type Downstream struct {
	adminClient      bilinadmin.BilinAdminClient
	employeeClient   bilinadmin.BilinEmployeeClient
	permissionClient bilinadmin.BilinPermissionClient
	memberClient     bmember.MemberClient
	openClient       open.OpenServiceClient
	prodClient       prod.ProdClient
}

func New(ctx context.Context, config *conf.Downstream) (downstream *Downstream) {
	downstream = &Downstream{}
	// 品牌
	downstream.adminClient, _ = newAdminClient(ctx, config.AdminURL)
	downstream.employeeClient, _ = newEmployeeClient(ctx, config.AdminURL)
	downstream.permissionClient, _ = newPermissionClient(ctx, config.AdminURL)
	// 会员
	downstream.memberClient, _ = newMemberClient(ctx, config.MemberURL)
	// 授权管理
	downstream.openClient, _ = newOpenClient(ctx, config.OpenURL)
	// 建立商品中心连接
	downstream.prodClient, _ = newProdClient(ctx, config.ProdURL)
	return
}
